using System.Text;
using MyAnt.Core.World;

namespace MyAnt.Core.Visualization.World
{
	public class SectorHtmlVisualizer : ISectorVisualizer
	{
		public object Visualize(Sector sector)
		{
			var sb = new StringBuilder();
			sb.Append("<table><tr>");
			for (var z = 0; z < sector.Height; z++)
			{
				sb.Append("<td><table>");
				for (var y = 0; y < sector.Depth; y++)
				{
					sb.Append("<tr>");
					for (var x = 0; x < sector.Width; x++)
					{
						var r = sector.Get(x, y, z);
						var c = "#000000";
						var s = "&nbsp;";
						switch (r)
						{
							case Resource.ResourceType.Air:
								c = "#ccccff";
								s = "Air";
								break;
							case Resource.ResourceType.Food:
								c = "#009900";
								s = "Food";
								break;
							case Resource.ResourceType.Grass:
								c = "#004400";
								s = "Grass";
								break;
							case Resource.ResourceType.Rock:
								c = "#999999";
								s = "Rock";
								break;
							case Resource.ResourceType.Sand:
								c = "#772277";
								s = "Sand";
								break;
							case Resource.ResourceType.Waste:
								c = "#990000";
								s = "Waste";
								break;
							case Resource.ResourceType.Water:
								c = "#000088";
								s = "Water";
								break;
						}
						sb.Append("<td style='width:20px;height:20px;background-color:" + c + "' title=" + s + "></td>");
					}
					sb.Append("</tr>");
				}
				sb.Append("</table></td>");
			}
			sb.Append("</tr></table>");
			return sb.ToString();
		}
	}
}